#include "Sensor_Threshold.h"
#include "driver_max6692.h"
#include "typedef.h"
#include "MmcDef.h"
#include "driver_adc.h"
#include "Config.h"

uint8 TempSensor_Scan(Sensor* pSensor)
{
	static uint8 temp[4]={0};
	static uint32 counter = 0;
	const static uint32 MAX_COUNT = 100*MS_COUNT;

	if(counter++ >= MAX_COUNT)
	{
		counter = 0;
	    Send_OneShot();
		Read_Max6692Temperature(temp);
	}

	if(pSensor->m_SensorId == TEMPERATURE1_SENSOR_ID)
	{
		return temp[0];
	}
	else if(pSensor->m_SensorId == TEMPERATURE2_SENSOR_ID)
	{
		return  temp[2];
	}
	/*
	else if(pSensor->m_SensorId == TEMPERATURE3_SENSOR_ID)
	{
		return  temp[2];
	}
	else if(pSensor->m_SensorId == TEMPERATURE4_SENSOR_ID)
	{
		return  temp[3];
	}
	*/
	return 0;
}

uint8 VoltageSensor_Scan(Sensor* pSensor)
{
	uint8 value = 0;
    uint16 vol_mv = 0;
    uint16 vol_fv = 0;
	
	if(pSensor->m_SensorId == VOLTAGE33_SENSOR_ID)
	{
		vol_mv = ADC_Convert(1);

		value = (vol_mv * 33 * 200) / 102400;
	}
	if(pSensor->m_SensorId == VOLTAGE12_SENSOR_ID)
	{
		vol_fv = ADC_Convert(3);
		value = (vol_fv * 33 * 502) / 102400;
	}

	return value;
}

